#!/usr/bin/python3

import sys
import repo_path

import dep_graph.cache

__HELP__ = """
remove.py @target

@target is specified like so:
 - //path/to/file:rule
 - rel_path/to/file:rule
 - :rule
"""

if __name__ == '__main__':
  try:
    if len(sys.argv) < 1:
      print(sys.argv)
      print(__HELP__)
      exit()

    BUILD_ROOT, rule_adjust, lib_dir = repo_path.getPathConsts(__file__)

    with dep_graph.cache.FileBackedCachedGraph(
        'bin/__graph__/newgraph.db') as graph:
      for filename in sys.argv[1:]:
        key = repo_path.pathToKey(filename, rule_adjust)
        graph.delete_gen_rule_with_key(key)

  except repo_path.Error as e:
    print(e)
